package com.oocl.dataprocess.printer;

import java.util.ArrayList;
import java.util.Set;
import java.util.TreeSet;

import com.oocl.dataprocess.comparator.BirthComparator;
import com.oocl.dataprocess.comparator.IdComparator;
import com.oocl.dataprocess.pojo.Customer;

public class Printer {
	public static void print(String flag,ArrayList<Customer> s){
		if("birth".equalsIgnoreCase(flag)){
			Set<Customer> set = new TreeSet<Customer>(new BirthComparator());
			for(Customer customer: s){
				set.add(customer);
			}
			System.out.println("ID"+"\t\t"+"名字"+"\t\t"+"邮箱"+"\t\t"+"性别"+"\t\t"+"生日");
			for(Customer c:set){
				System.out.println(c.getId()+"\t\t"+c.getName()+"\t\t"+c.getEmial()+"\t\t"+c.getSex()+"\t\t"+c.getBirth());
			}
			
		}else if("id".equalsIgnoreCase(flag)){
			Set<Customer> set = new TreeSet<Customer>(new IdComparator());
			for(Customer customer: s){
				set.add(customer);
			}
			System.out.println("ID"+"\t\t"+"名字"+"\t\t"+"邮箱"+"\t\t"+"性别"+"\t\t"+"生日");
			for(Customer c:set){
				System.out.println(c.getId()+"\t\t"+c.getName()+"\t\t"+c.getEmial()+"\t\t"+c.getSex()+"\t\t"+c.getBirth());
			}
		}
	}
	public static void printXML(ArrayList<Customer> s){
		Set<Customer> set = new TreeSet<Customer>(new IdComparator());
		for(Customer customer: s){
			set.add(customer);
		}
		System.out.println("<Customers>");
		for (Customer customer : set) {
		System.out.println("\t<Customer id=\"" + customer.getId() + "\">");
		System.out.println("\t\t<name>" + customer.getName() + "</name>");
		System.out
		.println("\t\t<birth>" + customer.getBirth() + "</birth>");
		System.out.println("\t\t<sex>" + customer.getSex() + "</sex>");
		System.out
		.println("\t\t<email>" + customer.getEmial() + "</email>");
		System.out.println("\t</Customer>");
		}
		System.out.println("</Customers>");
	
	}
}
